function RTabset() {
	var div = document.createElement("div");
	this.ui = div;
	this.ui.model = this;
	
	var table = document.createElement("table");
	table.className="RTabset";
	div.insertBefore(table);
	this.table = table;
	
	var row=table.insertRow();
	this.row=row;
	row.model=this;
	
	this.tabs=new Array();
}
RTabset.prototype={
	add: function(caption, src) {
		var td = this.row.insertCell();
		td.className="RTabset";
		td.innerHTML = caption;
		td.caption=caption;
		td.unselectable = "on";
		td.onclick=this.mouseClickHandler;
		td.ondblclick=this.doubleClickHandler;
		td.index=this.tabs.length;
		td.model=this;
		
		var f = document.createElement("iframe");
		this.ui.insertBefore(f);
		f.width="100%";
		f.height="100%"
		f.frameBorder=0;
		f.contentWindow.document.write("<center style=\"font-family:verdana;font-size:9pt\">LOADING...</center>");
		f.contentWindow.document.close();
		f.src=src;
		f.style.position="absolute";
		f.style.zIndex=0;
		
		var page=new Object();
		this.tabs[td.index] = page
		page.td = td;
		page.frame = f;
		return td.index;
	},
	remove: function(index) {
		// hide page frame, remove the tab
		// index is 0-based
		var p=this.tabs[index];
		p.frame.style.zIndex=0;
		p.frame.style.visibility="hidden";
		this.row.deleteCell(index);

		// move pages after this index one position forward
		for (var i=index+1; i<this.tabs.length;++i) {
			var page=this.tabs[i];
			page.td.index=i-1;
			this.tabs[i-1]=page;			
		}
		this.tabs.length=this.tabs.length-1;

		// set current selected page
		if (this.tabs.length == 0) 
			return;
		if (this.tabs.length == index)
			this.select(index-1);
		else 
			this.select(index);
	},
	removeAll: function() {while (this.getPageCount() > 0) this.remove(0);},
	getPageCount: function() {return this.tabs.length;},
	getIndexByCaption: function(caption) {
		for (var i=0; i<this.tabs.length;++i) {
			if (this.tabs[i].td.caption==caption)
				return i;
		}
		return -1;
	},
	select: function(index) {
		// index is 0-based
		for (var i=0; i<this.tabs.length;++i) {
			var page = this.tabs[i];
			page.td.className = "RTabset";
			page.frame.style.zIndex=0;
		}
		var page = this.tabs[index];
		page.td.className = "RTabsetSelected";
		page.frame.style.zIndex=10;
		/*
		var s = "selected: " + index + " " + page.frame.src + "\n";
		for (var i=0;i<this.tabs.length;++i) {
			s += i + " " + this.tabs[i].frame.src + "\n";
		}
		document.getElementById("a").innerText=s;
		*/
	},
	showIn: function(id) {
		document.getElementById(id).innerHTML="";
		document.getElementById(id).appendChild(this.ui);
	},
	mouseClickHandler: function() {
		// "this" is a td
		this.model.select(this.index);
	},
	doubleClickHandler: function() {
		// "this" is a td
		this.model.remove(this.index);
	}
}
